#ifndef PLAYLISTSERVER_H
#define PLAYLISTSERVER_H

//size of a message packet
#define MESSAGE_SIZE 128
//size of packet when we are receiving data from a file
#define DATA_SIZE 1024

#define PORT 4998

#include "../Common/Observer.h"
#include "../Common/Runnable.h"
#include "../Common/Playlist.h"
#include "../Common/Socket.h"

#include <vector>
#include <iostream>
#include <fstream>
#include <string>

/*-------------------------------------------------------------------------------------------
--
--	CLASS: PlaylistServer
--
--	Date: March 22, 2010
--
--	REVISIONS (Date and Description):
--
--	DESIGNER: Brad Paugh
--
--	PROGRAMMER: Brad Paugh
--
--  INTERFACE: class PlaylistServer : public Runnable, public Observer
--
--  RETURNS: N/A
--
--	NOTES: Program class for the Playlist Server. Sends/receives playlist data to all
--         connected clients. Playlist data could be the song names and the number of votes
--         a song has.
--
-------------------------------------------------------------------------------------------*/
class PlaylistServer : public Runnable, public Observer
{
	public:
		PlaylistServer();
		void runServer();
		inline Playlist* getPlaylist() { return &playlist_; }
        void run ();
	
	private:
		void acceptThread();
		void receiveThread(Socket* clientSocket);
		static void threadStart(void* param);
		void removeSocket(Socket* s);
		void sendPlaylistToAll();
		void sendPlaylistToClient(Socket* clientSock);
		void handleVote(std::string filename);
        void receiveFile(std::string filename, Socket* clientSocket, OVERLAPPED* overlapped);
        void notify (Observable *observable, int eventCode);

		//current playlist
		Playlist playlist_;
		//current connected clients
		std::vector<Socket*> connections_;
};

#endif
